package interceptor;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

import entity.Users;

public class LoginInterceptor extends  AbstractInterceptor { 

	private static final long serialVersionUID = 1L;
	
	public String intercept(ActionInvocation invocation) throws Exception {
		Users user = (Users) ActionContext.getContext().getSession().get("loginUser");
		System.out.println("拦截ing");
		String actionName = invocation.getProxy().getActionName();
		if ("Users_login".equals(actionName)) { // 如果是执行 login就不拦截；
			System.out.println("actionName: " + actionName);
			return invocation.invoke();
		}
		else {
			if (user == null) {
				System.out.println("actionName: " + actionName);
				return "tologin";
			}
			else {
				return invocation.invoke();
			}
		}
	}


}
